<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
function showHideParent(val)
{
	if(val == 'yes') {
		document.getElementById('show_parent').style.display = "";
	}
	if(val == 'no') {
		document.getElementById('show_parent').style.display = "none";
		document.getElementById('parent_page').value = "";
	}
}
function ValidatePage(frm)
{
	var parent_page = document.getElementById('parent_page').value;
	var page_name = document.getElementById('page_name').value;
	var page_id = document.getElementById('page_id').value;

	if(document.getElementById('sub_page_yes').checked == true && parent_page == "") {
		alert("Select Parent Page Name");
		return false;
	}
	if(page_name == "") {
		alert("Page Name is empty");
		return false;
	}

	else {
		
		if(page_id == "") {
			document.getElementById('process').value = 'add';
		}
		else {
			document.getElementById('process').value = 'edit';
		}
		document.frm.submit();
	}
	return false;
}
</script>
<?php
$query = mysql_query("select id,`page_name`, `sub_page`, `parent_page`, `link_name`, `image_name`, 
					 `stored_image_name`,`maincontent`,`meta_title`, `meta_content`, `meta_keywords`, `active_status`
					 from page where id='".$_REQUEST['_d']."'") or die(mysql_error());

$res = mysql_fetch_array($query);

if($res["active_status"] == 1) {
	$active_status = "checked";
}
else {
	$deactive_status = "checked";
}

if($res["sub_page"] == 1) {
	$yes_status = "checked";
	$display_style = '';
}
else {
	$no_status = "checked";
	$display_style = 'display:none;';
}

?>
<table border="0" width="100%" align="center">
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">
    Add Page</span>&nbsp; 
	<!--<input type="button" name="addnew" value="Add New" onclick="return show();" />-->
	</td>
	<td width="40%" align="right" class="font12">
    <a href="index.php" class="font12">Manage Pages</a></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
<form name="formPage" method="post" action="action.php" onSubmit="return ValidatePage(this);">
<table width="99%" align="center" border="0"  class="list">
<tr>
	<td align="right" width="250">Is Sub Page*</td>
    <td align="left"><input name="sub_page" id="sub_page_yes" type="radio"  value="1" <?php echo $yes_status;?> onclick="showHideParent('yes')"/>&nbsp;Yes &nbsp;&nbsp;
  <input  name="sub_page" id="sub_page_no" type="radio" value="0" <?php echo $no_status;?> onclick="showHideParent('no')"/>&nbsp;No</td>
</tr>
<tr id="show_parent" style="<?php echo $display_style;?>">
	<td align="right" width="250">Parent Page*</td>
    <td align="left">
    <select name="parent_page" id="parent_page">
    	<option value="" ></option>
     <?php 
	 if($res['id'] != "") {
		 $where_cond = " AND id != '".$res['id']."'";
		 if($res['parent_page'] != "0") {
			 $where_cond .= " and parent_page != '".$res['parent_page']."'";
		 }
	 }
	$qry = mysql_query("select id,page_name from page where active_status = '1' $where_cond") or die(mysql_error());
	while($row=mysql_fetch_array($qry)) {
		if($row['id'] == $res['parent_page']) {
			echo '<option value="'.$row['id'].'" selected>'.$row['page_name'].'</option>';
		}
		else {
			echo '<option value="'.$row['id'].'">'.$row['page_name'].'</option>';
		}
		
	}
	?>
    </select></td>
</tr>
<tr>
	<td align="right" width="250">Page*</td>
    <td align="left"><input class="text" name="page_name"  id="page_name" type="text" value="<?php echo $res['page_name'];?>"/></td>
</tr>
<tr>

    <td align="left" colspan="2">
    	Page Content
     <textarea name="maincont" id="maincont" class="textarea" cols="25" rows="5"><?php echo stripslashes(($res['maincontent']));?></textarea>
     <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
    </td>
</tr>
<!--<tr>
	<td align="right" width="250">Meta title</td>
    <td align="left"><input class="text" name="meta_title" id="meta_title" type="text" value="<?php echo $res['meta_title'];?>"/></td>
</tr>
<tr>
	<td align="right" width="250">Meta Keywords</td>
    <td align="left"><textarea class="text" name="meta_keywords" id="meta_keywords" cols="50" rows="5"><?php echo $res['meta_keywords'];?></textarea></td>
</tr>
<tr>
	<td align="right" width="250">Meta Description</td>
    <td align="left"><textarea class="text" name="meta_desc" id="meta_desc" cols="50" rows="5"><?php echo $res['meta_content'];?></textarea></td>
</tr>-->
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio"  value=1 <?php echo $active_status;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value=0 <?php echo $deactive_status;?>/>&nbsp;Deactive</td>
</tr>
<tr>
	<td align="right" width="150"></td>
    <td align="left">
    <input name="page_id" id="page_id" type="hidden" value="<?php echo $res['id'];?>"/>
    <input name="module" id="module" type="hidden" value="page"/>
    <input name="process" id="process" type="hidden" value=""/>
    <input type="submit" value="Submit" name="save_gadgettech">&nbsp;<input type="reset" name="reset" value="Clear" /></td>
</tr>
</table>
</form>